<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>资源管理</title>
<link rel="stylesheet" type="text/css" href="../res/css/common.css"/>
<link rel="stylesheet" type="text/css" href="../res/easyui1.5.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../res/easyui1.5.3/themes/icon.css">
<script type="text/javascript" src="../res/easyui1.5.3/jquery.min.js"></script>
<script type="text/javascript" src="../res/easyui1.5.3/jquery.easyui.min.js"></script>
<script src="../res/easyui1.5.3/locale/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>
<script src="../res/easyui1.5.3/easyui-utils.js" type="text/javascript" charset="utf-8"></script>
<script src="../res/js/tools.js" type="text/javascript" charset="utf-8"></script>
<script type="application/javascript">
	$(function(){
		// 初始化添加权限时的下拉树
		$('#pidTree').combotree('loadData',[{"id":0,"text":"系统根节点","iconCls":"icon-save","children":[{"id":1,"text":"权限管理","checked":true,"children":[{"id":2,"text":"资源管理"},{"id":3,"text":"角色管理"},{"id":4,"text":"角色管理"}]},{"id":5,"text":"部门管理","checked":true,"children":[{"id":6,"text":"运营中心"},{"id":7,"text":"会员单位"},{"id":8,"text":"经济公司"},{"id":9,"text":"居间"},{"id":10,"text":"经纪人"}]}]}]); 
	});
		
	/**
	 * 打开添加对话框 
	 */
	function openAddDialog(){
		$('#updateDialogForm').form("clear");
		openDialog('updateDialog', '添加资源');
	}
		
	/**
	 * 打开资源修改对话框
	 */
	function openUpdateDialog(){
		var row = getDatagridSelectedRow("datagridTable", "请选择要编辑的数据");
		//$("#ff").load(row);
		$("#dd").dialog("open");
		$('#updateDialogForm').form("load", row);
		openDialog('updateDialog', '修改资源');
	}
	
	/**
	 * 格式化显示类型
	 * @param {Object} value
	 * @param {Object} row
	 * @param {Object} index
	 */
	function formatterType(value,row,index){
		var typeStr = "未知类型";
		switch(value){
			case 0:
			typeStr = "导航条";
			break;
			case 1:
			typeStr = "导航菜单";
			break;
			case 2:
			typeStr = "页面按钮";
			break;
		}
		return typeStr;
	}
	
	/**
	 * 提交修改的数据
	 */
	function submitUpdateForm(){
		var obj = $('#updateDialogForm').form("getData", true);
		if($('#updateDialogForm').form("validate")){
			doAjax("../json/success.json", "GET", obj, true, function(result){
				showMsg(result.msg);
				if(result.code == AJAX_HANDLE_SUCCESS){
					closeDialog("updateDialog");
					// 表格数据重新加载
					$("#datagridTable").treegrid("reload");
				}
			});
		}
	}
	
	/**
	 * 提交查询form 
	 */
	function submitQueryForm(){
		var obj = $('#queryForm').form("getData", true);
		doAjax("../json/success2.json", "GET", obj, true, function(result){
			if(result.msg != ""){
				showMsg(result.msg);
			}
			if(result.code == AJAX_HANDLE_SUCCESS){
				// 填充加载到的数据
				$("#datagridTable").treegrid("loadData", result.data);
			}
		});
	}
</script>
</head>
<body>
<table id="datagridTable" class="easyui-treegrid" fit="true"
        data-options="method:'get', 
        url:'../json/resourceList.json',
        fitColumns:true,
        singleSelect:true,
        idField:'id',   
    		treeField:'name',
        pagination:true,
        rownumbers:true,
        toolbar:'#datagridTableToolBtns'
      	">  
    <thead>  
        <tr>  
        	<th data-options="field:'id', checkbox:true, align:'center'">ID</th>
            <th data-options="field:'name', width:140">名称</th>
            <th data-options="field:'pid', hidden:'true'">父节点id</th>  
            <th data-options="field:'action', width:80">操作标识</th>  
            <th data-options="field:'icon', width:40">图标</th>  
            <th data-options="field:'type', width:40, formatter:formatterType">类型</th>  
            <th data-options="field:'description',width:100">描述</th>   
            <th data-options="field:'createTime',width:60">创建时间</th>
            <th data-options="field:'updateTime',width:60">修改时间</th>
        </tr>  
    </thead>  
</table>

<!--表格工具区域-->
<div id="datagridTableToolBtns">
	<a href="javascript:openAddDialog();" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
	<a href="javascript:openUpdateDialog();" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
	<span>|</span>
	<form id="queryForm" class="i-b">
		名称：<input name="name" class="easyui-textbox" />
		创建日期：<input name="startTime" class="easyui-datetimebox" editable="false"/>到<input name="endTime" class="easyui-datetimebox" editable="false"/>
		<a href="javascript:submitQueryForm();" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">查询</a>
	</form>
</div>
<!-- 工具区域结束 -->

<!-- 添加/修改资源信息 -->
<div id="updateDialog" class="easyui-dialog" style="width:400px;height:400px;"  
        data-options="iconCls:'icon-save',resizable:true,modal:true, close:true,closed:true, buttons:'#dialogBtns'">  
	<form id="updateDialogForm" method="post" class="dialogForm">  
		<input type="hidden" name="id" id="id" value="-1" />
		<div class="row">  
	        <label for="name">父节点资源:</label>  
	        <select id="pidTree" name="pid" class="easyui-combotree" style="width:200px;"  
        data-options="required:true"></select>  
	    </div>
	    <div class="row"> 
	        <label for="name">资源名称:</label>  
	        <input class="easyui-validatebox" type="text" name="name" data-options="required:true" />  
	    </div>  
	    <div class="row">
	        <label for="type">资源类型:</label>  
	        <select id="typeSelectBox" class="easyui-combobox" name="type" style="width:200px;height: 40px;">  
			    <option value="0">导航条</option>
			    <option value="1">导航菜单</option>
			    <option value="2">页面按钮</option>
			</select>
	    </div>
	    <div class="row">
	        <label for="icon">资源图标:</label>  
	        <select id="iconSelectBox" class="easyui-combobox" name="icon" style="width:200px;">  
			    <option value="0">图标1</option>
			    <option value="1">图标2</option>
			    <option value="2">图标3</option>
			</select>
	    </div>
	    <div class="row">
	        <label for="action">资源标识:</label>  
	        <input class="easyui-validatebox" type="text" name="action" data-options="required:true" />
	    </div>
	    <div class="row">
	        <label for="description" style="vertical-align: top;">资源描述:</label>  
	        <textarea name="description" style="width: 200px; height: 100px;"></textarea>
	    </div>
	</form>  
</div>
<div id="dialogBtns" style="text-align: center;">
	<a href="javascript:submitUpdateForm();" class="easyui-linkbutton" style="width: 40px;">提交</a>
</div>
<!-- 添加/修改资源信息 结束-->
</body>
</html>
